home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 June / Macworld (1998-06).dmg / Shareware World / Comms & Internet / HTML and CSS modes / HTML and CSS Modes / htmlMode.tcl < prev    next >
Text File  |  1998-04-05  |  40KB  |  1,094 lines

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  HTML mode 2.1: tools for editing HTML documents
  4.  # 
  5.  #  FILE: "htmlMode.tcl"
  6.  #                                    created: 95-04-26 14.49.04 
  7.  #                                last update: 98-03-25 20.18.17 
  8.  #  Author: Johan Linde
  9.  #  E-mail: <jl@theophys.kth.se>
  10.  #     www: <http://bach.theophys.kth.se/~jl/Alpha.html>
  11.  #  
  12.  # Version: 2.1
  13.  # 
  14.  # version 0.24 (16 July 95) by Scott W. Brim <swb1@cornell.edu>
  15.  # version 1.0 -- 2.1 (March 98) by Johan Linde <jl@theophys.kth.se>
  16.  #
  17.  # Copyright 1996-1998 by Johan Linde
  18.  #  
  19.  # This software may be used freely, and distributed freely, as long as the 
  20.  # receiver is not obligated in any way by receiving it.
  21.  #  
  22.  # If you make improvements to this file, please share them!
  23.  # 
  24.  # ###################################################################
  25.  ##
  26.  
  27. if {[alpha::package vsatisfies ${alpha::version} 7.1b1]} {
  28. alpha::mode HTML 2.1 htmlMenu \
  29.   {*.html *.htm *.shtml *.HTML *.HTM *.SHTML } {
  30.     htmlMenu htmlUtilsMenu electricBraces electricSemicolon electricReturn electricTab
  31. } {
  32.     addMenu     htmlMenu
  33.     addMenu     htmlUtilsMenu
  34. } uninstall {
  35.     set __dir [file dirname [procs::find htmlMenu]]
  36.     foreach __file {Mode 40 Custom Elems Engine Entities HomePageUtils Menu StatusBar Utils} {
  37.         catch {removeFile $__dir:html${__file}.tcl}
  38.     }
  39.     catch {removeFile "$HOME:Tcl:Completions:HTMLCompletions.tcl"}
  40.     if {[procs::find cssMenu] == ""} {
  41.         catch {removeFile $__dir:hctsmsl.tcl}
  42.         catch {removeFile $__dir:hctsmslShared.tcl}
  43.         catch {removeFile $__dir:hctsmslMenu.tcl}
  44.         catch {removeFile "$HOME:Help:HTML Help"}
  45.         catch {removeFile "$HOME:Tcl:Completions:CSSCompletions.tcl"}
  46.     }
  47. } maintainer {
  48.     "Johan Linde" jl@theophys.kth.se <http://www.theophys.kth.se/~jl/Alpha.html>
  49. } help {file "HTML Help"}
  50. catch {unset HTMLmodeVars(elecRBrace)}
  51. catch {unset HTMLmodeVars(elecLBrace)}
  52. catch {unset HTMLmodeVars(electricSemi)}
  53. catch {unset HTMLmodeVars(electricTab)}
  54. } else {
  55. ;alpha::mode HTML 2.1 htmlMenu \
  56.   {*.html *.htm *.shtml *.HTML *.HTM *.SHTML } {htmlMenu htmlUtilsMenu} {
  57.     addMenu     htmlMenu
  58.     addMenu     htmlUtilsMenu
  59. } uninstall {
  60.     set __dir [file dirname [procs::find htmlMenu]]
  61.     foreach __file {Mode 40 Custom Elems Engine Entities HomePageUtils Menu StatusBar Utils} {
  62.         catch {removeFile $__dir:html${__file}.tcl}
  63.     }
  64.     catch {removeFile "$HOME:Tcl:Completions:HTMLCompletions.tcl"}
  65.     if {[procs::find cssMenu] == ""} {
  66.         catch {removeFile $__dir:hctsmsl.tcl}
  67.         catch {removeFile $__dir:hctsmslShared.tcl}
  68.         catch {removeFile $__dir:hctsmslMenu.tcl}
  69.         catch {removeFile "$HOME:Help:HTML Help"}
  70.         catch {removeFile "$HOME:Tcl:Completions:CSSCompletions.tcl"}
  71.     }
  72. } maintainer {
  73.     "Johan Linde" jl@theophys.kth.se <http://www.theophys.kth.se/~jl/Alpha.html>
  74. } help {file "HTML Help"}
  75. # Electric left brace?
  76. newPref f elecRBrace 1 HTML
  77. # Electric right brace?
  78. newPref f elecLBrace 1 HTML
  79. # Electric semi colon?
  80. newPref f electricSemi 1 HTML
  81. newPref f electricTab 1 HTML
  82. }
  83.  
  84. # called by Alpha to load HTML in.  
  85. proc htmlMenu {} {}
  86. proc htmlUtilsMenu {} {}
  87.  
  88. # A few procs so that HTML mode runs with Alpha 7.0.
  89. if {![alpha::package vsatisfies ${alpha::version} 7.0p5]} {
  90. proc is::Whitespace {anyString} {
  91.     return [regexp "^\[ \t\r\n\]*$" $anyString]
  92. }
  93. proc is::UnsignedInteger {str1} {
  94.     return [regexp {^[0-9]+$} [string trim $str1]]
  95. }
  96. proc is::PositiveInteger {str1} {
  97.     if [is::UnsignedInteger $str1] {
  98.         return [expr $str1 > 0]
  99.     }
  100.     return 0
  101. }
  102. }
  103. if {![alpha::package vsatisfies ${alpha::version} 7.1b1]} {
  104. proc bind::fromArray {arr bindarr {unbind 0} {mode {}}} {
  105.     upvar $arr ar
  106.     upvar $bindarr br
  107.     set r {}
  108.     if $unbind {
  109.         set bindcmd "unbind"
  110.     } else {
  111.         set bindcmd "bind"
  112.     }
  113.     foreach a [array names ar] {
  114.         if {[set b $ar($a)] != ""} {
  115.             if [info exists br($a)] {
  116.                 catch {eval $bindcmd [keys::toBind $b] [list $br($a)] $mode}
  117.             } else {
  118.                 beep; message "Bad bind-array entry '$a'"
  119.             }
  120.         }
  121.     }
  122. }
  123. }
  124.  
  125.  
  126. #===============================================================================
  127. # Global variables and their management
  128. #===============================================================================
  129.  
  130. # Unsetting some old prefs
  131. foreach _tmp {htmlPackageToUse hideNetscape hideIE inclEventHandler hideStyleAttrs useAttsApplyToDialogs} {
  132.     catch {unset HTMLmodeVars($_tmp)}
  133. }
  134.  
  135. set htmlIconTxt {"Netscape Navigator 3" "Netscape Navigator 4" "Netscape Communicator" "Internet Explorer" Cyberdog MacLynx Mosaic}
  136. set htmlIcons {•135 •293 •294 •295 •281 •296 •942}
  137.  
  138. # Menu icons
  139. newPref v htmlMenuIcon •294 HTML
  140. newPref v htmlUtilsMenuIcon •281 HTML
  141.  
  142. if {$HTMLmodeVars(htmlMenuIcon) == $HTMLmodeVars(htmlUtilsMenuIcon)} {
  143.     foreach _tmp $htmlIcons {
  144.         if {$HTMLmodeVars(htmlMenuIcon) != $_tmp} {
  145.             set HTMLmodeVars(htmlUtilsMenuIcon) $_tmp
  146.             lappend modifiedModeVars {htmlUtilsMenuIcon HTMLmodeVars}
  147.             break
  148.         }
  149.     }
  150. }
  151.  
  152. set htmlMenu $HTMLmodeVars(htmlMenuIcon)
  153. set htmlUtilsMenu $HTMLmodeVars(htmlUtilsMenuIcon)
  154.  
  155. # Line width
  156. newPref v fillColumn 75 HTML
  157. newPref v leftFillColumn 0 HTML
  158. # word breaking and word wrapping
  159. newPref v wordBreak {\w+} HTML
  160. newPref v wordBreakPreface {(\W)} HTML
  161. newPref v wrapBreak {[\w_]+} HTML
  162. newPref v wrapBreakPreface {([^\w_])} HTML
  163. newPref f wordWrap    1 HTML
  164.  
  165. # Indentation
  166. newPref f indentAPPLET 0 HTML
  167. newPref f indentBLOCKQUOTE 0 HTML
  168. newPref f indentBODY 0 HTML
  169. newPref f indentCENTER 0 HTML
  170. newPref f indentDIR 1 HTML
  171. newPref f indentDIV 0 HTML
  172. newPref f indentDL 1 HTML
  173. newPref f indentFIELDSET 0 HTML
  174. newPref f indentFORM 0 HTML
  175. newPref f indentFRAMESET 0 HTML
  176. newPref f indentHEAD 0 HTML
  177. newPref f indentMAP 0 HTML
  178. newPref f indentMENU 1 HTML
  179. newPref f indentMULTICOL 0 HTML
  180. newPref f indentNOEMBED 0 HTML
  181. newPref f indentNOFRAMES 0 HTML
  182. newPref f indentNOSCRIPT 0 HTML
  183. newPref f indentOBJECT 0 HTML
  184. newPref f indentOL 1 HTML
  185. newPref f indentOPTGROUP 0 HTML
  186. newPref f indentP 0 HTML
  187. newPref f indentSELECT 0 HTML
  188. newPref f indentTABLE 1 HTML
  189. newPref f indentTR 1 HTML
  190. newPref f indentUL 1 HTML
  191. set htmlIndentElements {HEAD BODY P DIV BLOCKQUOTE CENTER MULTICOL OBJECT NOEMBED OL UL DIR MENU DL
  192. FORM FIELDSET SELECT OPTGROUP TABLE TR FRAMESET NOFRAMES MAP APPLET NOSCRIPT}
  193.  
  194. # browsers
  195. if {![info exists browserSig] && [catch {getFileSig [icGetPref -t 1 Helper•http]} browserSig]} {set browserSig MOSS}
  196. # Browser signatures
  197. newPref v browsers {MOSS MSIE} HTML
  198.  
  199. newPref v prefixString    "<!-- " HTML
  200. newPref v suffixString    " -->" HTML
  201.  
  202. # Paths to footer files.
  203. newPref v footers {} HTML
  204. # Tag color
  205. newPref v tagColor        blue HTML
  206. # Attribute color
  207. newPref v attributeColor magenta HTML
  208. # Simple coloring?
  209. newPref f simpleColoring 0 HTML
  210. # Should elements be lower case?
  211. newPref f useLowerCase    0 HTML
  212. # Should •'s be inserted?
  213. newPref    f useTabMarks    1 HTML
  214. # Is <p> a container?
  215. newPref f pIsContainer    1 HTML
  216. # Are LI DT and DD containers 
  217. newPref f lidtAreContainers 0  HTML
  218. # A window cache with frames.
  219. newPref v windows        {} HTML
  220. # When browser is launched, should it be brought to front?
  221. newPref    f browseInForeground    1 HTML
  222. # Save without asking when sending file to browser?
  223. newPref f saveWithoutAsking 0 HTML
  224. # Default list of commonly used character entities
  225. newPref v defaultCommonChars {"less than" "greater than" "ampersand" "nonbreak space"} HTML
  226. # List of commonly used character entities
  227. newPref v commonChars $HTMLmodeVars(defaultCommonChars) HTML
  228. # Never ask about extensions?
  229. newPref f hideExtensions 0 HTML
  230. # Never ask about deprecated elements and attributes?
  231. newPref f hideDeprecated 0 HTML
  232. # Attributes globally not asked about at first
  233. newPref v dontaskforAttributes {} HTML
  234. # Attributes globally never asked about
  235. newPref v neveraskforAttributes {} HTML
  236. # Attributes globally always asked about
  237. newPref v alwaysaskforAttributes {} HTML
  238. # Beep when asking for attributes in the status bar?
  239. newPref f promptNoisily 1 HTML
  240. # Flash status bar for first attribute?
  241. newPref f flashStatusBar 1 HTML
  242. # Input from dialog windows or status bar?
  243. newPref f useBigWindows 1 HTML
  244. # Change attributes in dialog windows or status bar?
  245. newPref f changeInBigWindows 1 HTML
  246. # Cmd-double-click on non text file link opens file?
  247. newPref f openNonTextFile 1 HTML
  248. # Return on non text file in home page window opens file?
  249. newPref f homeOpenNonTextFile 1 HTML
  250. # Check anchors in links?
  251. newPref f checkAnchors 1 HTML
  252. # Case sensistive link checking?
  253. newPref f caseSensitive 0 HTML
  254. # Check links with Big Brother?
  255. newPref f useBigBrother 0 HTML
  256. newPref f checkInFront 1 HTML
  257. newPref f useBBoptions 1 HTML
  258. newPref f ignoreRemote 0 HTML
  259. newPref f ignoreLocal 0 HTML
  260. # Folder for HTML manual.
  261. newPref v manualFolder "$HOME:HTML mode manual" HTML
  262. newPref v manualStartPage 0 HTML
  263. # FTP servers
  264. newPref v FTPservers {} HTML
  265. # Last modified string
  266. newPref v lastModified "Last modified" HTML
  267. # 'Insert include tags' only inserts tags, and not the file?
  268. newPref f includeOnlyTags 1 HTML
  269. # Color JavaScript keywords?
  270. newPref f JavaScriptColoring 0 HTML
  271. # Color of JavaScript keywords
  272. newPref v JavaScriptColor    magenta HTML
  273. # Color of strings
  274. newPref v stringColor green HTML
  275. # Color of JavaScript comments
  276. newPref v JavaCommentColor red HTML
  277. # Color CSS keywords?
  278. newPref f CSSColoring 0 HTML
  279. # Color of CSS keywords
  280. newPref v CSSColor cyan HTML
  281.  
  282.  
  283. # These attributes are URLs.
  284. set htmlURLAttr    {HREF= SRC= LOWSRC= ACTION= USEMAP= BACKGROUND= CODEBASE= PLUGINSPAGE=
  285. DYNSRC= CLASSID= DATA= CITE= LONGDESC= PROFILE=}
  286. # These element attributes are colors
  287. set htmlColorAttr    {BGCOLOR= TEXT= LINK= VLINK= ALINK= COLOR= BORDERCOLOR=
  288. BORDERCOLORDARK= BORDERCOLORLIGHT=}
  289. # These attributes are windows
  290. set htmlWindowAttr {TARGET=}
  291. # Special cases with URLs, colors and windows
  292. set htmlSpecURL {}
  293. set htmlSpecColor {}
  294. set htmlSpecWindow {}
  295. # These elements can be in document HEAD.
  296. set htmlHeadElements1 {BASE ISINDEX LINK META STYLE SCRIPT OBJECT}
  297. # These elements are plug-ins.
  298. set htmlPlugins {EMBED LIVEAUDIO LIVEVIDEO "QUICKTIME MOVIE" "QUICKTIME VR" REALAUDIO}
  299. # HTML mode version
  300. set htmlVersion 2.1
  301.  
  302. # Register eventhandler for Big Brother events
  303. eventHandler Bbth Chkd htmlBbthChkdHandler 
  304.  
  305. # Used by fillParagraph
  306. set htmlParaCommands {html|head|title|body|h[1-6]|p|div|blockquote|center|address|pre|multicol}
  307. append htmlParaCommands {|br|hr|wbr|basefont|ul|ol|li|dir|menu|dl|dd|dt|form|input}
  308. append htmlParaCommands {|select|option|textarea|caption|table|tr|frameset|frame|noframes}
  309. append htmlParaCommands {|map|area|applet|param|script|noscript|layer|ilayer|nolayer|base|link|meta|isindex}
  310. append htmlParaCommands {|col|colgroup|marquee|object|thead|tbody|tfoot}
  311.  
  312. #
  313. # Internal Globals
  314. #
  315. set htmlCurSel    ""
  316. set htmlIsSel    0
  317. set htmlAdditionExist 0
  318. set htmlHomePageWinList {}
  319. set homeTime 0
  320. set htmlNumBbthChecking 0
  321. set htmlHideDeprecated 0
  322. set htmlHideExtensions 0
  323. set htmlHideFrames 0
  324.  
  325. # Load other HTML mode files.
  326. foreach tmp {htmlEngine htmlElems htmlEntities htmlUtils hctsmslShared hctsmslMenu htmlMenu} {
  327.     if {[info exists cssModeIsLoaded] && ($tmp == "hctsmslMenu" || $tmp == "hctsmslShared")} {continue}
  328.     if { [catch {eval ${tmp}.tcl}] } {
  329.         beep
  330.         alertnote "Loading of ${tmp}.tcl failed"
  331.         return
  332.     }
  333. }
  334.  
  335. if {(!$HTMLmodeVars(useBigWindows) || !$HTMLmodeVars(changeInBigWindows)) && [catch {htmlStatusBar.tcl}] } {
  336.     beep
  337.     alertnote "Loading of htmlStatusBar.tcl failed"
  338.     return
  339. }
  340.  
  341. # Silently add missing menu.
  342. if {[info exists modeMenus(HTML)]} {
  343.     if {[lsearch -exact $modeMenus(HTML) htmlMenu] < 0} {
  344.         lappend modeMenus(HTML) htmlMenu
  345.     }
  346.     if {[lsearch -exact $modeMenus(HTML) htmlUtilsMenu] < 0} {
  347.         lappend modeMenus(HTML) htmlUtilsMenu
  348.     }
  349. }
  350. if {[info exists mode::features(HTML)]} {
  351.     if {[lsearch -exact [set mode::features(HTML)] htmlMenu] < 0} {
  352.         lappend mode::features(HTML) htmlMenu
  353.     }
  354.     if {[lsearch -exact [set mode::features(HTML)] htmlUtilsMenu] < 0} {
  355.         lappend mode::features(HTML) htmlUtilsMenu
  356.     }
  357. }
  358.  
  359. # Clean up tmp files
  360. if {[file exists $PREFS:HTMLtmp]} {
  361.     if {[file exists $PREFS:HTMLtmp:incl]} {catch {rm -r $PREFS:HTMLtmp:incl}}
  362.     if {[file exists $PREFS:HTMLtmp:xincl]} {catch {rm -r $PREFS:HTMLtmp:xincl}}
  363.     catch {rm $PREFS:HTMLtmp:*}
  364. }
  365.  
  366.  
  367. #
  368. # Read custom elements
  369. #
  370.  
  371. proc htmlReadAdditions {} {
  372.     global PREFS htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
  373.     global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
  374.     global htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
  375.     global htmlSpecURL htmlSpecColor htmlSpecWindow htmlVersion htmlShownWarning
  376.  
  377.     html40.tcl
  378.     message "Loading custom elements…"
  379.     
  380.     
  381.     if {[catch {open $PREFS:HTMLadditions.tcl r} fid]} {
  382.         alertnote "Could not open the file HTMLAdditions.tcl with your custom elements."
  383.         return
  384.     }
  385.     set additions [read -nonewline $fid]
  386.     close $fid
  387.     set lines [split $additions "\n"]
  388.     set version [lindex $lines 0]
  389.     if {$version == $htmlVersion} {htmlReadAdditions0 $lines; return}
  390.     if {$version > $htmlVersion} {
  391.         regsub "\[^\n\]+" $additions $htmlVersion additions
  392.         set fid [open $PREFS:HTMLadditions.tcl w]
  393.         puts $fid $additions
  394.         close $fid
  395.         htmlReadAdditions0 $lines
  396.         return
  397.     }
  398.     set allattrs [htmlGetAllAttrs]
  399.     set newLines "$htmlVersion\n"
  400.     set changed 0
  401.     set tmpSpecURL ""
  402.     set tmpSpecColor ""
  403.     set tmpSpecWindow ""
  404.     foreach line [lrange $lines 1 end] {
  405.         set elem [lindex $line 0]
  406.         set command [lindex $line 1]
  407.         set elemExists [info exists htmlElemAttrOptional1($elem)]
  408.         if {$elemExists} {
  409.             foreach x [list AttrOptional1 AttrRequired1 AttrNumber1 AttrChoices1 EventHandler1] {
  410.                 if {[info exists htmlElem${x}($elem)]} {
  411.                     set $x [string toupper [set htmlElem${x}($elem)]]
  412.                 } else {
  413.                     set $x ""
  414.                 }
  415.             }
  416.             set attrs [concat $AttrOptional1 $AttrRequired1 $EventHandler1]
  417.             foreach at $attrs {
  418.                 if {[string trimright $at =] == $at} {
  419.                     lappend attrs "${at}="
  420.                 } else {
  421.                     lappend attrs [string trimright $at =]
  422.                 }
  423.             }
  424.         } else {
  425.             set attrs {}
  426.         }
  427.         set var [lindex $command 1]
  428.         foreach ucw [list URL Color Window] {
  429.             if {$var == "html${ucw}Attr"} {
  430.                 set att [lindex $command 2]
  431.                 if {[lsearch -exact [set html${ucw}Attr] $att] >=0} {
  432.                     # Already defined.
  433.                     set changed 1
  434.                 } elseif {[lsearch -exact $allattrs $att] >=0 || [lsearch -exact $allattrs [string trimright $att =]] >=0} {
  435.                     # Used for some other kind of attr.
  436.                     lappend ${ucw}SpecMaybe $att
  437.                     set changed 1
  438.                 } elseif {[lsearch -exact $attrs $att] >= 0} {
  439.                     # Attr already exists for elem.
  440.                     lappend ${ucw}Maybe $att
  441.                     set changed 1
  442.                 } else {
  443.                     append newLines "$line\n"
  444.                 }
  445.             }
  446.             if {$var == "htmlSpec${ucw}"} {
  447.                 set tmpadd [lrange $command 2 end]
  448.                 foreach x $tmpadd {
  449.                     regexp {[^!=]!?=(.*)} $x dum tmp
  450.                     # Only add if attr doesn't exist.
  451.                     if {[lsearch -exact $attrs $tmp] >= 0} {
  452.                         set changed 1
  453.                         set where [lsearch -exact $tmpadd $x]
  454.                         set tmpadd [lreplace $tmpadd $where $where]
  455.                     }
  456.                 }
  457.                 if {[llength $tmpadd]} {
  458.                     append newLines "[list $elem] \{lappend htmlSpec${ucw} $tmpadd\}\n"
  459.                     append tmpSpec${ucw} " " $tmpadd
  460.                 }
  461.             }
  462.         }
  463.         if {[lsearch {htmlURLAttr htmlColorAttr htmlWindowAttr htmlSpecURL \
  464.         htmlSpecColor htmlSpecWindow} $var] < 0} {
  465.             # If element doesn't exist, GO!
  466.             if {!$elemExists} {
  467.                 append newLines "$line\n"
  468.                 regsub "html" $command "tmp" command
  469.                 eval $command
  470.                 continue
  471.             }
  472.             # Skip these vars if element exists.
  473.             if {[string match "htmlElemKeyBinding*" $var] || [string match "htmlElemProc*" $var] ||
  474.             $var == "htmlPlugins"} {
  475.                 set changed 1
  476.                 continue
  477.             }
  478.             regexp {([^\(]+)\(([^\)]+)\)[ ]+(.+)} [lrange $command 1 end] dummy var arg added
  479.             set added [string trimleft [string trimright $added \}] \{]
  480.             foreach c $added {
  481.                 if {$var == "htmlElemAttrChoices1"} {
  482.                     regexp {[^=]*=} $c tmp
  483.                     # Don't add choices if they exist or if attr isn't a choice attr.
  484.                     if {[lsearch -exact $AttrChoices1 $c] >= 0 || ([lsearch -exact $attrs $tmp] >= 0 &&
  485.                     [lsearch $AttrChoices1 "${tmp}*"] < 0) } {
  486.                         set changed 1
  487.                         set where [lsearch -exact $added $c]
  488.                         set added [lreplace $added $where $where]
  489.                     }
  490.                 } else {
  491.                     if {$var == "htmlElemAttrNumber1"} {
  492.                         regexp {[^=]*=} $c tmp
  493.                     } else {
  494.                         set tmp [string toupper $c]
  495.                     }
  496.                     # Don't add attrs which exist.
  497.                     if {[lsearch -exact $attrs $tmp] >= 0} {
  498.                         set changed 1
  499.                         set where [lsearch -exact $added $c]
  500.                         set added [lreplace $added $where $where]
  501.                     }
  502.                 }
  503.             }
  504.             if {[llength $added]} {
  505.                 append newLines "[list $elem] \{lappend ${var}($arg) $added\}\n"
  506.                 regsub "html" $var "tmp" var
  507.                 eval "lappend ${var}($arg) $added"
  508.             }
  509.         }
  510.     }
  511.     foreach ucw [list URL Color Window] {
  512.         if {[info exists ${ucw}SpecMaybe]} {
  513.             foreach m [set ${ucw}SpecMaybe] {
  514.                 foreach e [array names tmpElemAttrRequired1] {
  515.                     if {[lsearch -exact $tmpElemAttrRequired1($e) $m] >= 0 && \
  516.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  517.                         append newLines "[list $e] \{lappend htmlSpec${ucw} ${e}=[string trimright $m =]\}\n"
  518.                     } 
  519.                 }
  520.                 foreach e [array names tmpElemAttrOptional1] {
  521.                     if {[lsearch -exact $tmpElemAttrOptional1($e) $m] >= 0 && \
  522.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  523.                         append newLines "[list $e] \{lappend htmlSpec${ucw} ${e}=[string trimright $m =]\}\n"
  524.                     } 
  525.                 }
  526.             }
  527.         }
  528.         if {[info exists ${ucw}Maybe]} {
  529.             foreach m [set ${ucw}Maybe] {
  530.                 set foundit 0
  531.                 foreach e [array names tmpElemAttrRequired1] {
  532.                     if {[lsearch -exact $tmpElemAttrRequired1($e) $m] >= 0 && \
  533.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  534.                         append newLines "[list $e] \{lappend html${ucw}Attr $m\}\n"
  535.                         set foundit 1
  536.                         break
  537.                     } 
  538.                 }
  539.                 if {$foundit} {continue}
  540.                 foreach e [array names tmpElemAttrOptional1] {
  541.                     if {[lsearch -exact $tmpElemAttrOptional1($e) $m] >= 0 && \
  542.                     [lsearch -exact [set tmpSpec$ucw] "$e!=[string trimright $m =]"] < 0} {
  543.                         append newLines "[list $e] \{lappend html${ucw}Attr $m\}\n"
  544.                         break
  545.                     } 
  546.                 }
  547.             }
  548.         }    
  549.     }
  550.     
  551.     if {$newLines != "$htmlVersion\n"} {htmlReadAdditions0 [split [string trimright $newLines "\n"] "\n"]}
  552.     if {$changed} {
  553.         beep
  554.         if {[lindex [dialog -w 300 -h 270 -b "Clean up" 20 240 100 260 \
  555.         -b "Leave it" 120 240 200 260 -t "Some of your custom elements are supported by this\
  556.         version of HTML mode." 10 10 290 45 -t "Choose 'Clean up' to update your file with custom\
  557.         elements and to avoid this alert next time you run Alpha.\
  558.         If you do so, some elements will not be defined correctly if you go back to\
  559.         a previous version of HTML mode." 10 50 290 150 -t "Choose 'Leave it' to leave your file\
  560.         with custom elements untouched. If you do so, the submenu 'Extend', where you can add new custom\
  561.         elements, will be disabled." 10 160 290 225] 1]} {
  562.             set htmlShownWarning 1
  563.             return
  564.         }
  565.     }
  566.     if {$newLines == "$htmlVersion\n"} {
  567.         removeFile $PREFS:HTMLadditions.tcl
  568.     } else {
  569.         set fid [open $PREFS:HTMLadditions.tcl w]
  570.         puts -nonewline $fid $newLines
  571.         close $fid
  572.     }
  573. }
  574.  
  575. proc htmlReadAdditions0 {lines} {
  576.     global htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
  577.     global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
  578.     global htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
  579.     global htmlSpecURL htmlSpecColor htmlSpecWindow htmlAdditionExist htmlShownWarning
  580.     
  581.     foreach line [lrange $lines 1 end] {
  582.         if {[catch {eval [lindex $line 1]}]} {
  583.             alertnote "There is an error in the file HTMLAdditions.tcl with your custom elements."
  584.             set htmlShownWarning 1
  585.             break
  586.         }
  587.     }
  588.     set htmlAdditionExist 1
  589. }
  590.  
  591. #
  592. # Color support
  593. #
  594.  
  595. proc htmlColorizing {{changing 0}} {
  596.      global HTMLmodeVars HTMLwords htmlElemAttrOptional1 htmlElemAttrRequired1
  597.      global htmlElemEventHandler1 PREFS htmlElemKeyBinding
  598.      
  599.      set HTMLKeyWords {}
  600.     if {[info exists HTMLwords]} {set HTMLKeyWords $HTMLwords}
  601.  
  602.     if {!$HTMLmodeVars(simpleColoring)} {
  603.         # All HTML elements
  604.         set allHTMLwords [concat {A ABBR ACRONYM ADDRESS APPLET AREA B BASE 
  605.         BASEFONT BDO BGSOUND BIG BLINK BLOCKQUOTE BODY BR BUTTON CAPTION 
  606.         CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM EMBED 
  607.         FIELDSET FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I 
  608.         IFRAME ILAYER IMG INPUT INS ISINDEX KBD KEYGEN LABEL LAYER LEGEND 
  609.         LI LINK MAP MARQUEE MENU META MULTICOL NOBR NOEMBED NOFRAMES 
  610.         NOLAYER NOSCRIPT OBJECT OL OPTGROUP OPTION P PARAM PRE Q S SAMP 
  611.         SCRIPT SELECT SERVER SMALL SPACER SPAN STRIKE STRONG STYLE SUB SUP TABLE 
  612.         TBODY TD TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR WBR} [array names htmlElemKeyBinding]]
  613.     
  614.         foreach elem $allHTMLwords {
  615.             lappend allHTMLkeywords "<${elem}" "/${elem}"
  616.         }
  617.         # All attributes
  618.         set attributeWords {ABBR= ABOVE= ACCEPT-CHARSET= ACCEPT= ACCESSKEY= 
  619.         ACTION= ALIGN= ALINK= ALT= ARCHIVE= AUTOPLAY= AUTOSTART= AXIS= 
  620.         BACKGROUND= BEHAVIOR= BELOW= BGCOLOR= BGPROPERTIES= BORDER= 
  621.         BORDERCOLOR= BORDERCOLORDARK= BORDERCOLORLIGHT= CELLPADDING= 
  622.         CELLSPACING= CHALLENGE= CHAR= CHAROFF= CHARSET= CHECKED CITE= 
  623.         CLASS= CLASSID= CLEAR= CLIP= CODE= CODEBASE= CODETYPE= COLOR= COLS= 
  624.         COLSPAN= COMPACT CONSOLE= CONTENT= CONTROLLER= CONTROLS CONTROLS= 
  625.         COORDS= CORRECTION= DATA= DATETIME= DECLARE DEFER DIR= DIRECTION= 
  626.         DISABLED DYNSRC= ENCTYPE= FACE= FOR= FOV= FRAME= FRAMEBORDER= 
  627.         FRAMESPACING= GUTTER= HEADERS= HEIGHT= HIDDEN= HREF= HREFLANG= 
  628.         HSPACE= HTTP-EQUIV= ID= ISMAP LABEL= LANG= LANGUAGE= LEFT= 
  629.         LEFTMARGIN= LINK= LONGDESC= LOOP= LOWSRC= MARGINHEIGHT= 
  630.         MARGINWIDTH= MAXLENGTH= MAYSCRIPT MEDIA= METHOD= MULTIPLE NAME= 
  631.         NODE= NOHREF NOLABELS= NORESIZE NOSHADE NOWRAP OBJECT= PAGEX= 
  632.         PAGEY= PAN= PLAYEVERYFRAME= PLUGINSPAGE= POINT-SIZE= PROFILE= 
  633.         PROMPT= READONLY REL= REV= ROWS= ROWSPAN= RULES= SCHEME= SCOPE= 
  634.         SCROLLAMOUNT= SCROLLDELAY= SCROLLING= SELECTED SHAPE= SIZE= SPAN= 
  635.         SRC= STANDBY= START= STYLE= SUMMARY= TABINDEX= TARGET= TEXT= TILT= 
  636.         TITLE= TOP= TOPMARGIN= TYPE= USEMAP= VALIGN= VALUE= VALUETYPE= 
  637.         VISIBILITY= VLINK= VSPACE= WIDTH= WRAP= Z-INDEX=}
  638.         # Custom element attributes
  639.         if {[file exists $PREFS:HTMLadditions.tcl] && ![catch {open $PREFS:HTMLadditions.tcl} fid]} {
  640.             set lines [lrange [split [read -nonewline $fid] "\n"] 1 end]
  641.             close $fid
  642.             foreach line $lines {
  643.                 set cmd [lindex $line 1]
  644.                 set added ""
  645.                 regexp {([^\(]+)\(([^\)]+)\)[ ]+(.+)} [lrange $cmd 1 end] dummy var arg added
  646.                 set added [string trimleft [string trimright $added \}] \{]
  647.                 if {$var == "htmlElemAttrRequired1" || $var == "htmlElemAttrOptional1"} {
  648.                     foreach attr $added {
  649.                         if {[lsearch -exact $attributeWords $attr] < 0} {
  650.                             lappend attributeWords $attr
  651.                         }
  652.                     }
  653.                 }
  654.             }
  655.         }
  656.         lappend attributeWords "FILE=" "FORM="
  657.         # JavaScript keywords.
  658.         set JavaScriptWords {break case continue default delete do export for import in 
  659.         function if else new return switch this typeof var void while with true false 
  660.         onAbort= onBlur= onChange= onClick= onDblClick= onError= onFocus= 
  661.         onKeyDown= onKeyPress= onKeyUp= onLoad= onMouseDown= onMouseMove= 
  662.         onMouseOut= onMouseOver= onMouseUp= onReset= onSelect= onSubmit= onUnload=}
  663.         # CSS keywords
  664.         set CSSwords {font-family font-style font-variant font-weight font-size font 
  665.         color background-color background-image background-repeat background-attachment
  666.         background-position background word-spacing letter-spacing text-decoration
  667.         vertical-align text-transform text-align text-indent line-height
  668.         margin-top margin-right margin-bottom margin-left margin padding-top padding-right
  669.         padding-bottom padding-left padding border-top-width border-right-width
  670.         border-bottom-width border-left-width border-width border-color border-style
  671.         border-top border-right border-bottom border-left border width height float clear
  672.         display white-space list-style-type list-style-image list-style-position list-style
  673.         @import important}
  674.         
  675.         if {!$changing} {
  676.             regModeKeywords -i "<" -i ">" -I $HTMLmodeVars(tagColor) \
  677.                 -s $HTMLmodeVars(stringColor)  -b "/*" "*/" -e "//" HTML {}
  678.         }
  679.         if {$HTMLmodeVars(JavaScriptColoring) || $HTMLmodeVars(CSSColoring)} {
  680.             set col $HTMLmodeVars(JavaCommentColor)
  681.         } else {
  682.             set col none
  683.         }
  684.         regModeKeywords -a -c $col HTML
  685.         if {$HTMLmodeVars(JavaScriptColoring)} {
  686.             set col $HTMLmodeVars(JavaScriptColor)
  687.         } else {
  688.             set col none
  689.         }
  690.         regModeKeywords -a -k $col HTML $JavaScriptWords
  691.         if {$HTMLmodeVars(CSSColoring)} {
  692.             set col $HTMLmodeVars(CSSColor)
  693.         } else {
  694.             set col none
  695.         }
  696.         regModeKeywords -a -k $col HTML $CSSwords
  697.         regModeKeywords -a -k $HTMLmodeVars(tagColor) \
  698.         HTML [concat $HTMLKeyWords $allHTMLkeywords]
  699.         regModeKeywords -a -k $HTMLmodeVars(attributeColor) HTML $attributeWords
  700.         regModeKeywords -a -k $HTMLmodeVars(JavaCommentColor) HTML {"<!--" "-->" "#INCLUDE" "/#INCLUDE"
  701.         "#LASTMODIFIED" "/#LASTMODIFIED" "#DOCINDEX" "/#DOCINDEX"}
  702.     } else {
  703.         regModeKeywords -b "<" ">" -c $HTMLmodeVars(tagColor) \
  704.         -k $HTMLmodeVars(tagColor) HTML $HTMLKeyWords
  705.     }
  706. }
  707.  
  708. # Change color when a color variable is changed.
  709. proc htmlChangeColorizing {flag} {
  710.     global HTMLmodeVars
  711.     set msg 0
  712.     switch -glob $flag {
  713.         simpleColoring {
  714.             htmlColorizing
  715.             set msg 1
  716.         }
  717.         JavaScriptColoring -
  718.         attributeColor -
  719.         CSSColoring {
  720.             if {!$HTMLmodeVars(simpleColoring)} {
  721.                 htmlColorizing 1
  722.             }
  723.         }
  724.         tagColor {
  725.             if {$HTMLmodeVars(simpleColoring)} {
  726.                 regModeKeywords -a -c $HTMLmodeVars(tagColor) HTML
  727.             } else {
  728.                 regModeKeywords -a -i "<" -i ">" -I $HTMLmodeVars(tagColor) HTML
  729.                 htmlColorizing 1
  730.             }
  731.         }
  732.         JavaScriptColor {
  733.             if {$HTMLmodeVars(JavaScriptColoring) && !$HTMLmodeVars(simpleColoring)} {
  734.                 htmlColorizing 1
  735.             }
  736.         }
  737.         JavaCommentColor {
  738.             if {($HTMLmodeVars(JavaScriptColoring) || $HTMLmodeVars(CSSColoring)) && !$HTMLmodeVars(simpleColoring)} {
  739.                 regModeKeywords -a -c $HTMLmodeVars(JavaCommentColor) HTML
  740.             }
  741.         }
  742.         CSSColor {
  743.             if {$HTMLmodeVars(CSSColoring) && !$HTMLmodeVars(simpleColoring)} {
  744.                 htmlColorizing 1
  745.             }
  746.         }    
  747.         stringColor {
  748.             if {!$HTMLmodeVars(simpleColoring)} {
  749.                 regModeKeywords -a -s $HTMLmodeVars(stringColor) HTML
  750.             }
  751.         }
  752.     }
  753.     refresh
  754.     if {$msg} {message "Coloring may not change until you switch to another window."}
  755. }
  756.  
  757. trace variable browserSig w htmlToggleBrowser2
  758.  
  759. # Dialog to set HTML mode variables.
  760. proc HTMLmodifyFlags {{which General}} {
  761.     global HTMLmodeVars modifiedModeVars htmlIconTxt htmlIcons htmlMenu htmlUtilsMenu
  762.     
  763.     if {$which == "Attributes"} {htmlGlobalAttrsPrefs; return}
  764.     
  765.     set box [eval html${which}PrefsBox]
  766.     set allFlags [eval html${which}Flags]
  767.  
  768.     set attrTxt {"status bar" "dialog boxes"}
  769.     set manTxt {"first page in manual" "table of contents without frames" "table of contents with frames"}
  770.     set values [eval [concat dialog -w 460 -h 315 -b OK 20 285 85 305 -b Cancel 110 285 175 305 $box]]
  771.     if {[lindex $values 1]} {return}
  772.     if {$which == "General" && [lindex $values 22] == [lindex $values 23]} {
  773.         alertnote "You can't use the same menu icon for both menus. Menu icon changes are ignored."
  774.         set allFlags [lrange $allFlags 0 18]
  775.     }
  776.     set i 1
  777.     if {$which == "General"} {incr i}
  778.     foreach flag $allFlags {
  779.         global $flag
  780.         incr i
  781.         set val [lindex $values $i]
  782.         if {$flag == "useBigWindows" || $flag == "changeInBigWindows"} {set val [lsearch -exact $attrTxt $val]}
  783.         if {$flag == "manualStartPage"} {set val [lsearch -exact $manTxt $val]}
  784.         if {[string match "*Icon" $flag]} {set val [lindex $htmlIcons [lsearch $htmlIconTxt $val]]}
  785.         if {$HTMLmodeVars($flag) != $val} {
  786.             set $flag $val
  787.             set HTMLmodeVars($flag) $val
  788.             lappend modifiedModeVars [list $flag HTMLmodeVars]
  789.             if {[string match "*Color*" $flag]} {htmlChangeColorizing $flag}
  790.             if {[string match "*Icon" $flag]} {
  791.                 removeMenu [set [string trim $flag "Icon"]]
  792.                 set [string trim $flag "Icon"] $val
  793.                 eval htmlBuild[string trim $flag Iconhtml]
  794.             }
  795.         }
  796.     }
  797. }
  798.  
  799. proc htmlGeneralPrefsBox {} {
  800.     global HTMLmodeVars htmlIconTxt htmlIcons alpha::colors
  801.     
  802.     set attrTxt {"status bar" "dialog boxes"}
  803.     set manTxt {"first page in manual" "table of contents without frames" "table of contents with frames"}
  804.  
  805.     set box "-t {General HTML mode Preferences} 100 10 450 30 \
  806.     -m {{Page 1 of preferences} {Page 1 of preferences} {Page 2 of preferences} {Page 3 of preferences}} 100 35 300 55 \
  807.     -n {Page 1 of preferences} \
  808.     -c {Bring browser to front when sending a window to it} $HTMLmodeVars(browseInForeground) 10 65 450 80\
  809.     -c {Save window without asking when sending it to the browser} $HTMLmodeVars(saveWithoutAsking) 10 85 450 100 \
  810.     -c {Set tags in lower case} $HTMLmodeVars(useLowerCase) 10 105 200 120 \
  811.     -c {Use template stops (•)} $HTMLmodeVars(useTabMarks) 10 125 450 140 \
  812.     -c {<P> has a closing tag </P>} $HTMLmodeVars(pIsContainer) 10 145 450 160 \
  813.     -c {<LI>, <DT> and <DD> have closing tags} $HTMLmodeVars(lidtAreContainers) 10 165 450 180 \
  814.     -t {Give attributes in}  10 185 150 200\
  815.     -m {[list [lindex $attrTxt $HTMLmodeVars(useBigWindows)]] {dialog boxes} {status bar}} 155 185 450 205 \
  816.     -t {Change attributes in} 10 210 150 225 \
  817.     -m {[list [lindex $attrTxt $HTMLmodeVars(changeInBigWindows)]] {dialog boxes} {status bar}} 155 210 450 230 \
  818.     -c {Beep for first attribute (applies only if you use the status bar)} $HTMLmodeVars(promptNoisily) 10 235 450 250 \
  819.     -c {Flash status bar for first attribute} $HTMLmodeVars(flashStatusBar) 10 255 450 270 \
  820.     -n {Page 2 of preferences} \
  821.     -c {Simple coloring} $HTMLmodeVars(simpleColoring) 10 65 450 80 \
  822.     -t {Color of HTML tags:} 10 85 150 100 \
  823.     -m [list [concat $HTMLmodeVars(tagColor) ${alpha::colors}]] 160 85 310 105 \
  824.     -t {Color of attributes:} 10 110 150 125 \
  825.     -m [list [concat $HTMLmodeVars(attributeColor) ${alpha::colors}]] 160 110 310 130 \
  826.     -t {Color of strings:} 10 135 150 150 \
  827.     -m [list [concat $HTMLmodeVars(stringColor) ${alpha::colors}]] 160 135 310 155 \
  828.     -t {'Help' opens} 10 160 95 175 \
  829.     -m {[concat [list [lindex $manTxt $HTMLmodeVars(manualStartPage)]] $manTxt]} 100 160 450 180 \
  830.     -c {Cmd-double-clicking on non-text file link opens file} $HTMLmodeVars(openNonTextFile) 10 190 450 205 \
  831.     -c {Return on non-text file in home page window opens file} $HTMLmodeVars(homeOpenNonTextFile) 10 210 450 225 \
  832.     -c {'Insert include tags' only inserts tags} $HTMLmodeVars(includeOnlyTags) 10 230 450 245 \
  833.     -n {Page 3 of preferences} \
  834.     -t {'Last modified' text} 10 65 150 80 -e [list $HTMLmodeVars(lastModified)] 160 65 450 80 \
  835.     -t {HTML menu icon:} 10 90 170 105 \
  836.     -m [list [concat [list [lindex $htmlIconTxt [lsearch $htmlIcons $HTMLmodeVars(htmlMenuIcon)]]] $htmlIconTxt]] 180 90 450 110 \
  837.     -t {HTML Utilities menu icon:} 10 115 170 130 \
  838.     -m [list [concat [list [lindex $htmlIconTxt [lsearch $htmlIcons $HTMLmodeVars(htmlUtilsMenuIcon)]]] $htmlIconTxt]] 180 115 450 135"
  839.  
  840.     return $box
  841. }
  842.  
  843. proc htmlGeneralFlags {} {
  844.     return [list browseInForeground saveWithoutAsking useLowerCase useTabMarks pIsContainer lidtAreContainers \
  845.     useBigWindows changeInBigWindows promptNoisily flashStatusBar simpleColoring \
  846.     tagColor attributeColor stringColor manualStartPage openNonTextFile homeOpenNonTextFile \
  847.     includeOnlyTags lastModified htmlMenuIcon htmlUtilsMenuIcon]
  848. }
  849.  
  850. proc htmlIndentationPrefsBox {} {
  851.     global HTMLmodeVars htmlIndentElements
  852.     set box "-t {HTML mode Indentation Preferences} 100 10 450 30 \
  853.     -t {Indent the content of} 10 40 450 55"
  854.     set ww 70; set hh 10
  855.     foreach ind $htmlIndentElements {
  856.         append box " -c $ind $HTMLmodeVars(indent${ind}) $hh $ww [expr $hh + 100] [expr $ww + 15]"
  857.         incr ww 20
  858.         if {$ww > 200} {
  859.             set ww 70
  860.             incr hh 110
  861.         }
  862.     }
  863.     return $box
  864. }
  865.  
  866. proc htmlIndentationFlags {} {
  867.     global htmlIndentElements
  868.     return "indent[join $htmlIndentElements " indent"]"
  869. }    
  870.  
  871. if {![alpha::package vsatisfies ${alpha::version} 7.1b1]} {
  872. proc htmlJavaScriptPrefsBox {} {
  873.     global HTMLmodeVars alpha::colors
  874.     set box "-t {HTML mode JavaScript and CSS Preferences} 100 10 450 30 \
  875.     -c {Electric left braces} $HTMLmodeVars(elecLBrace) 10 35 450 50 \
  876.     -c {Electric right braces} $HTMLmodeVars(elecRBrace) 10 55 450 70 \
  877.     -c {Electric semicolon} $HTMLmodeVars(electricSemi) 10 75 450 90 \
  878.     -c {Color JavaScript keywords} $HTMLmodeVars(JavaScriptColoring) 10 95 450 110\
  879.     -t {Color of JavaScript keywords:} 10 115 215 130 \
  880.     -m [list [concat $HTMLmodeVars(JavaScriptColor) ${alpha::colors}]] 220 115 360 135 \
  881.     -c {Color CSS keywords} $HTMLmodeVars(CSSColoring) 10 165 450 180\
  882.     -t {Color of CSS keywords:} 10 185 215 200 \
  883.     -m [list [concat $HTMLmodeVars(CSSColor) ${alpha::colors}]] 220 185 360 205 \
  884.     -t {Color of JavaScript and CSS comments:} 10 210 270 225 \
  885.     -m [list [concat $HTMLmodeVars(JavaCommentColor) ${alpha::colors}]] 275 210 420 230"
  886.     
  887.     return $box
  888. }
  889.  
  890. proc htmlJavaScriptFlags {} {
  891.     return [list  elecLBrace elecRBrace electricSemi\
  892.     JavaScriptColoring JavaScriptColor CSSColoring CSSColor JavaCommentColor]
  893. }
  894. } else {
  895. proc htmlJavaScriptPrefsBox {} {
  896.     global HTMLmodeVars alpha::colors
  897.     set box "-t {HTML mode JavaScript and CSS Preferences} 100 10 450 30 \
  898.     -c {Color JavaScript keywords} $HTMLmodeVars(JavaScriptColoring) 10 35 450 50\
  899.     -t {Color of JavaScript keywords:} 10 55 215 70 \
  900.     -m [list [concat $HTMLmodeVars(JavaScriptColor) ${alpha::colors}]] 220 55 360 75 \
  901.     -c {Color CSS keywords} $HTMLmodeVars(CSSColoring) 10 105 450 120\
  902.     -t {Color of CSS keywords:} 10 125 215 140 \
  903.     -m [list [concat $HTMLmodeVars(CSSColor) ${alpha::colors}]] 220 125 360 145 \
  904.     -t {Color of JavaScript and CSS comments:} 10 150 270 165 \
  905.     -m [list [concat $HTMLmodeVars(JavaCommentColor) ${alpha::colors}]] 275 150 420 270"
  906.     
  907.     return $box
  908. }
  909.  
  910. proc htmlJavaScriptFlags {} {
  911.     return [list JavaScriptColoring JavaScriptColor CSSColoring CSSColor JavaCommentColor]
  912. }
  913. }
  914.  
  915. proc htmlCheckingPrefsBox {} {
  916.     global HTMLmodeVars
  917.     set box "-t {HTML mode Checking Links Preferences} 100 10 450 30 \
  918.     -t {These settings apply when you check links with Alpha:} 10 40 450 55 \
  919.     -c {Check anchors} $HTMLmodeVars(checkAnchors) 10 60 450 75 \
  920.     -c {Case sensitive checking (slower)} $HTMLmodeVars(caseSensitive) 10 80 450 95 \
  921.     -t {These settings apply when you check links with Big Brother:} 10 105 450 120\
  922.     -c {Bring Big Brother to front when checking links} $HTMLmodeVars(checkInFront) 10 125 450 140\
  923.     -c {Use Big Brother's link check options} $HTMLmodeVars(useBBoptions) 10 145 450 160\
  924.     -c {Ignore remote links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreRemote) 30 165 450 180\
  925.     -c {Ignore local links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreLocal) 30 185 450 200"
  926.     return $box
  927. }
  928.  
  929. proc htmlCheckingFlags {} {
  930.     return [list checkAnchors caseSensitive checkInFront useBBoptions ignoreRemote ignoreLocal]
  931. }
  932.  
  933. proc htmlWordPrefsBox {} {
  934.     global HTMLmodeVars
  935.     set box "-t {HTML mode Word Wrapping Preferences} 100 10 450 30 \
  936.     -t {Line width:} 10 40 90 55 -e [list $HTMLmodeVars(fillColumn)] 100 40 140 55 \
  937.     -t characters 145 40 300 55 \
  938.     -t {The variables below determine which characters build up words, and the word wrapping. Normally\
  939.     there is no need to change them. Read about them in general manual if you want to change them.} \
  940.     10 70 450 130 \
  941.     -t wordBreak: 10 140 150 155 -e [list $HTMLmodeVars(wordBreak)] 155 140 450 155 \
  942.     -t wordBreakPreface: 10 165 150 180 -e [list $HTMLmodeVars(wordBreakPreface)] 155 165 450 180 \
  943.     -t wrapBreak: 10 190 150 205 -e [list $HTMLmodeVars(wrapBreak)] 155 190 450 205 \
  944.     -t wrapBreakPreface: 10 215 150 230 -e [list $HTMLmodeVars(wrapBreakPreface)] 155 215 450 230"
  945. }
  946.  
  947. proc htmlWordFlags {} {
  948.     return [list fillColumn wordBreak wordBreakPreface wrapBreak wrapBreakPreface]
  949. }
  950.  
  951. proc htmlGlobalAttrsPrefs {} {
  952.     global HTMLmodeVars modifiedModeVars
  953.     set attrs " ID= CLASS= STYLE= TITLE= LANG= DIR= onClick= onDblClick= \
  954.      onMouseDown= onMouseUp= onMouseOver= onMouseMove= onMouseOut= onKeyPress= onKeyDown= onKeyUp="
  955.     set alwaysask $HTMLmodeVars(alwaysaskforAttributes)
  956.     set dontask $HTMLmodeVars(dontaskforAttributes)
  957.     set hidden $HTMLmodeVars(neveraskforAttributes)
  958.     htmlUseAttrsDialog "HTML mode Attributes Preferences" $attrs "" alwaysask hidden dontask 1
  959.     set HTMLmodeVars(alwaysaskforAttributes) $alwaysask
  960.     set HTMLmodeVars(dontaskforAttributes) $dontask
  961.     set HTMLmodeVars(neveraskforAttributes) $hidden
  962.     lappend modifiedModeVars {alwaysaskforAttributes HTMLmodeVars} {dontaskforAttributes HTMLmodeVars} {neveraskforAttributes HTMLmodeVars}
  963. }
  964.  
  965. if {[file exists $PREFS:HTMLadditions.tcl]} {
  966.     if {[catch {htmlReadAdditions}]} {alertnote "An error occured while reading your custom elements."}
  967. }
  968. rename htmlReadAdditions ""
  969. rename htmlReadAdditions0 ""
  970.  
  971. htmlBuildMenu
  972. htmlBuildUtilsMenu
  973. htmlColorizing
  974. # Check that all home page folders exist.
  975. set tmp_notfind ""
  976. foreach tmp_hp $HTMLmodeVars(homePages) {
  977.     if {![file exists [lindex $tmp_hp 0]] || ![file isdirectory [lindex $tmp_hp 0]]} {
  978.         alertnote "Can't find the folder for the home page [lindex $tmp_hp 1][lindex $tmp_hp 2]"
  979.         set tmp_notfind "[lindex $tmp_hp 1][lindex $tmp_hp 2]"
  980.     }
  981. }
  982. if {$tmp_notfind != ""} {htmlHomePages $tmp_notfind}
  983. catch {unset tmp tmp_notfind tmp_hp}
  984.  
  985. # Define a couple of key bindings.
  986. if {[file exists "$PREFS:HTML:HTML entity keys"]} {
  987.     source "$PREFS:HTML:HTML entity keys"
  988. } else {        
  989.     if {![info exists htmlEntityKeys([list less than])]} {
  990.         set htmlEntityKeys([list less than]) "<U<B<I/,"
  991.         set htmlEntityKeysProc([list less than]) {htmlInsertCharacter "less than"}
  992.     }
  993.     if {![info exists htmlEntityKeys([list greater than])]} {
  994.         set htmlEntityKeys([list greater than]) "<U<B<I/."
  995.         set htmlEntityKeysProc([list greater than]) {htmlInsertCharacter "greater than"}
  996.     }
  997.     if {![info exists htmlEntityKeys(ampersand)]} {
  998.         set htmlEntityKeys(ampersand) "<U<B<I/7"
  999.         set htmlEntityKeysProc(ampersand) {htmlInsertCharacter ampersand}
  1000.     }
  1001.     if {![info exists htmlEntityKeys([list nonbreak space])]} {
  1002.         set htmlEntityKeys([list nonbreak space]) "<U<B<I/ "
  1003.         set htmlEntityKeysProc([list nonbreak space]) {htmlInsertCharacter "nonbreak space"}
  1004.     }
  1005.     htmlSaveCache "HTML entity keys" "array set htmlEntityKeys [list [array get htmlEntityKeys]]\rarray set htmlEntityKeysProc [list [array get htmlEntityKeysProc]]"
  1006. }
  1007.  
  1008. bind::fromArray htmlEntityKeys htmlEntityKeysProc 0 HTML
  1009. catch {unset htmlEntityKeys htmlEntityKeysProc}
  1010.  
  1011. proc htmlBindBraces {args} {
  1012.     global bind::LeftBrace bind::RightBrace
  1013.     eval bind [keys::toBind ${bind::LeftBrace}] htmlLeftBrace HTML
  1014.     eval bind [keys::toBind ${bind::RightBrace}] htmlRightBrace HTML
  1015. }
  1016. htmlBindBraces
  1017. trace variable bind::LeftBrace w htmlBindBraces
  1018. trace variable bind::RightBrace w htmlBindBraces
  1019.  
  1020. # Comment line
  1021. bind 'l' <C>  htmlCommentLine HTML
  1022.  
  1023.  
  1024. # Register hooks
  1025. hook::register saveHook htmlUpdateLastMod HTML
  1026. hook::register saveasHook htmlUpdateLastMod HTML
  1027. hook::register quitHook htmlQuitHook
  1028. hook::register closeHook htmlCloseHook Home
  1029. hook::register deactivateHook htmldeactivateHook Home
  1030. hook::register activateHook htmlActivateHook HTML
  1031. hook::register openHook htmlActivateHook HTML
  1032.  
  1033. proc HTML::OptionTitlebar {} {
  1034.     global htmlPopUptag
  1035.     return [set htmlPopUptag [htmlGetAttributes]]
  1036. }
  1037.  
  1038. proc HTML::OptionTitlebarSelect {item} {
  1039.     global htmlPopUptag
  1040.     if {[lsearch -exact $htmlPopUptag $item] >= 0} {
  1041.         htmlInsertAttributes $item
  1042.     } else {
  1043.         error "Not an attibute."
  1044.     }
  1045. }
  1046.  
  1047. if {![alpha::package vsatisfies ${alpha::version} 7.1b1]} {
  1048. proc htmlLeftBrace {} {
  1049.     global elecLBrace
  1050.     set old $elecLBrace
  1051.     if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
  1052.         set elecLBrace 0
  1053.     }
  1054.     catch {bind::LeftBrace}
  1055.     set elecLBrace $old
  1056. }
  1057. proc htmlRightBrace {} {
  1058.     global elecRBrace
  1059.     set old $elecRBrace
  1060.     if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
  1061.         set elecRBrace 0
  1062.     }
  1063.     catch {bind::RightBrace}
  1064.     set elecRBrace $old
  1065. }
  1066. } else {
  1067. proc htmlLeftBrace {} {
  1068.     global electricBraces
  1069.     set old $electricBraces
  1070.     if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
  1071.         set electricBraces 0
  1072.     }
  1073.     catch {bind::LeftBrace}
  1074.     set electricBraces $old
  1075. }
  1076. proc htmlRightBrace {} {
  1077.     global electricBraces
  1078.     set old $electricBraces
  1079.     if {![htmlIsInContainer SCRIPT] && ![htmlIsInContainer STYLE]} {
  1080.         set electricBraces 0
  1081.     }
  1082.     catch {bind::RightBrace}
  1083.     set electricBraces $old
  1084. }
  1085. }
  1086. if {[info exists cssModeIsLoaded] && $htmlVersion != $cssVersion} {
  1087.     alertnote "Warning: The versions of HTML mode and CSS mode may not be compatible.\
  1088.         Always install new versions of HTML mode and CSS mode simultaneously."
  1089. }
  1090.  
  1091. set htmlModeIsLoaded 1
  1092.  
  1093. message "HTML initialization complete."
  1094.